package com.nanjing.controler;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nanjing.entity.Myuser;
import com.nanjing.manager.LoginManager;

@Controller
public class LoginControler {
	public LoginControler() {
		// CharacterEncodingFilter
		System.out.println("common...");
	}

	@RequestMapping("/login")
	public String login(String userid, String passwd) {
		LoginManager lm = new LoginManager();
		Myuser myuser = new Myuser();
		System.out.println("login..." + userid + "    " + passwd);

		myuser.setUserid(userid);
		myuser.setPasswd(passwd);
		boolean flag = lm.isValid(myuser);
		System.out.println("-----flag:" + flag);
		if (flag == true) {
			lm.queryMyuser(userid);
			return "info";
		} else {
			return "login";
		}

	}

	/*
	 * public String login(Myuser myuser, Model m) {
	 * System.out.println("llllll.......");
	 * 
	 * LoginManager lm = new LoginManager();
	 * 
	 * m.addAttribute("uname", myuser.getUname()); m.addAttribute("userid",
	 * myuser.getUserid()); m.addAttribute("passwd", myuser.getPasswd());
	 * m.addAttribute("usex", myuser.getUsex()); m.addAttribute("uage",
	 * myuser.getUage());
	 * 
	 * System.out.println("login..." + myuser.getUname() + "    " +
	 * myuser.getPasswd()); boolean flag = lm.isValid(myuser); if (flag == true)
	 * { return "info"; } else { return "login"; }
	 * 
	 * }
	 */

	@RequestMapping("/regist")
	public String regist(Myuser myuser) {

		System.out.println("regist...." + myuser.getUname());
		LoginManager lm = new LoginManager();
		//lm.upDateMyuser(myuser);
		lm.addMyuser(myuser);
		return "login";
	}

	/*
	 * @RequestMapping("/info") public String showInfo(Model m) {
	 * System.out.println("info...."); m.addAttribute("uname"); return "info"; }
	 */
}
